<?php
use Core\Helper\ApplicationDirectoryHelper;

$allTemplate = $this->allTemplates;
?>

<div class="ad_title_ctn">
    <h2>Quản lý nhà hàng</h2>
</div>

<div class="ad_content_ctn">
    <div id="restaurant_grid"></div>
</div>

<script type="text/x-kendo-template" id="template">
    <div class="toolbar">
        <a class="k-button k-button-icontext  k-grid-edit"
           href="/admin/restaurant/add">
            <span class="k-icon k-add"></span>Tạo mới
        </a>
    </div>
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $(".restaurant_critetia_ctn").keyup( function(event) {
            if ( event.which == 13 ) {
                event.preventDefault();
                doSearch();
            }
        });


        dataSource = new kendo.data.DataSource({
            type: "jsonp",
            transport: {

                read: function(options) {
                    $.ajax( {
                        url: "<?php echo '/admin/restaurant/list'  ?>",
                        data: options.data, // the "data" field contains paging, sorting, filtering and grouping data
                        success: function(result) {
                            if(result.success){
                                options.success(result);
                                $('#error_ctn').html('');
                            }else{
                                $('#error_ctn').html(result.msg);
                                grid = $("#restaurant_grid").data("kendoGrid");
                                // cancel changes
                                grid.cancelChanges();
                            }
                        },
                        dataType: "json",
                        type: "POST"

                    });
                },



                destroy: function(options) {
                    $.ajax( {
                        url: "/admin/restaurant/remove?id="+options.data.id,
                        data: options.data,
                        success: function(result) {
                            if(result.success){
                                options.success(options.data.models);
                                $('#error_ctn').html('Xóa thành công.');
                            }else{
                                $('#error_ctn').html(result.msg);
                                grid = $("#restaurant_grid").data("kendoGrid");
                                // cancel changes
                                grid.cancelChanges();
                            }


                        },
                        dataType: "json",
                        type: "POST"

                    });
                }
            },
            schema: {
                model: {
                    id: "id",
                    fields: {
                        id: {editable: false,  type: "number" },
                        name: { type: "string" },
                        domain: { type: "string" },
                        email: { type: "string" },
                        phone: { type: "string" },
                        status: { type: "string" }



                    }
                },
                data: "rows",
                total: "total"
            },
//                    batch: true,
            pageSize: 3,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        });

        $("#restaurant_grid").kendoGrid({
            dataSource: dataSource,
            navigatable: true,
            pageable: true,

            columnMenu: true,
            sortable: true,
            resizable:true,
            toolbar:kendo.template($("#template").html()),

            columns: [
                { field: "name", title: "Tên", width: 100, template:" <a href='<?php echo '/admin/restaurant/edit?id='  ?>#= id #'>#= name #</a> " },
                { field: "domain", title: "Url", width: 120 },
                { field: "email", title: "template", width: 120 },
                { field: "phone", title: "template", width: 120 },
                { field: "status", title: "template", width: 120 }

            ]
        });



    });

    function doActive(me, restaurantId){

    }
</script>